#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>


float difftime_ms(struct timeval t2, struct timeval t1)
{
    return (float)(t2.tv_sec - t1.tv_sec)*1.0e3 + (float)(t2.tv_usec - t1.tv_usec)/1.0e3;
}


int bucle_cvWaitKey(int * wait)
{	
    int key;
    key = cvWaitKey(*wait) ;
    key = key & (0x0FFFFF ^ 0x020000);

    if(key == 'Q' || key == 'q')
    {
	return -1;
    }
    if (key>='0' && key <='9')
    {
	*wait = (key-(int)'0')*(key-(int)'0')*10;
	return 0;
    }
    else if (key == ' ')
    {
	*wait =0;
	return 0;
    }
    else if (key == 917503)
	return 0;

    return key;
}


int ntrace1[100];
int ntrace2[100];
void TRACE(int a, const char * data)
{
    if (data)
	printf("\n-------------(%d)-TRACE %d---%s----\n", a, ntrace1[a]++, data);
    else
	printf("\n-------------(%d)-TRACE %d----------\n", a, ntrace2[a]++);
    fflush(stdout);
}

void RESET_TRACE(int a)
{
    ntrace1[a] = 0;
    ntrace2[a] = 0;
}
